/* SuperHero Mod functions
*
* by the SuperHero Mod Development Team
*
* This file is provided as is (no warranties).
*/
#include <shconst>
#include <fun>

#pragma library SuperHero
#pragma library SheroPlugin

//*************************************************//
//******************** NATIVES ********************//
//*************************************************//

// Get Server Vars
native sh_server_info(ServerVars);

// Create Hero Native
//Will return hero ID
native sh_create_hero(name[]);
//Set heroe's info
native sh_hero_info(g_heroID,power[],help[]);
//Set hero bind
native sh_hero_bind(g_heroID,bool:keys = false);
//Set hero level
native sh_hero_level(g_heroID,level=0);

// Register a key down function for hero
// ex: sh_set_keydown(g_heroID,"hero_kd");
//native sh_set_keydown(heroID, keydownFunction[]);

// Register a key up function for hero
// ex: sh_set_keyup(g_heroID,"hero_ku");
//native sh_set_keyup(heroID,keyupFunction[]);

// Get/Set Users Superhero Info
native sh_get_user_xp(id);
native sh_set_user_xp(id,xp);

native sh_get_user_lvl(id);
native sh_set_user_lvl(id, lvl);

native sh_get_user_ban(id);
native sh_set_user_ban(id, ban = 0);

native sh_get_user_flag(id);
native sh_get_user_binds(id);
native sh_user_heronum(id);

//Returns players max hp/ap
native sh_max_hp(id);
native sh_max_ap(id);

//Set heroes variables
//1. HeroID
//2. Max Health
//3. Max Armor
native sh_set_hero_vars(heroID,maxHealth, maxArmor);

// 
native sh_set_hero_grav(heroID, cvarname[], numWeapons, weapons[]);

native sh_set_hero_speed(heroID, cvarname[], numWeapons, weapons[]);

//Check if user has this hero
//1. Player ID
//2. Hero ID
native sh_check_hero(id, heroID);


//*************************************************//
//**** TO BE USED WITH SuperHero Mod CORE ONLY ****//
//*************************************************//

// Add hero to user
//1. Player ID
//2. Hero Name
native sh_add_user_hero(id,heroName[]);

// Remove Hero from a user
//1. Player ID
//2. Hero Name
native sh_drop_user_hero(id,heroName[]);

// Clear all user xp/heros.
// 1. Player ID
// 2. Mode
//     |----1. xp/lvl/heroes
//     |----2. heroes only
native sh_clear_user(id, mode);


//* Get specified hero information *//

// Returns hero level
native sh_get_hero_lvl(heroID);

// Sets name to hero name
native sh_get_hero_name(heroID, name[], iLen);

// Sets power to heroes power
native sh_get_hero_power(heroID, power[], iLen);

// Sets help to heroes help info
native sh_get_hero_help(heroID, help[], iLen);

// Returns 1 for bind, 0 no bind
native sh_get_hero_bind(heroID);

// Returns Users XP Given
native sh_xpgiven(id);

// Stun player for certain time
native sh_stunplayer(id, Float:howLong, Float:speed = 320.0);



//*************************************************//
//******************* FORWARDS ********************//
//*************************************************//

// Called Every new round (after freezetime)
forward sh_round_start();

// Called Every New Round
forward sh_new_spawn( id );

// Called at the end of every round.
forward sh_end_round();

// Called when a hero is added/droped
forward sh_hero_init( id, heroID, mode);

// Called when a +/-power is executed
forward sh_hero_key( id, heroID, key);



//*************************************************//
//**************** BUILT IN NATIVES ***************//
//*************************************************//

// Start Ultimate Timer
native sh_utimer(id,g_heroID,Float:timer = 1.0);

// Status on Ultimate Timer. Returns 1/0.
// 1. Still in timer
// 0. Timer Finished
native sh_ustatus(id,g_heroID);

// Set user status on Ultimate Timer
native sh_uset(id,g_heroID, set);

// Set Screen flash
native sh_screenflash(id, red , green, blue, decisecs, alpha);

// Set Screen Shake
native sh_screenshake(id, amplitude, duration, frequency );

// Log a Kill
native sh_logkill(id, victim, weaponDescription[] );

// Add HP
native sh_addhp(id, hitPoints, maxHealth);

// Reload Ammo 
// 1. Drop
// 0. No drop
native sh_reloadammo(id, dropwpn = 0 );

// Deal extra damage
native sh_extradamage(id, attacker, damage, weaponDescription[], headshot = 0 )

// Give godmode for certain time
native sh_godplayer(id, howLong);

//*************************************************//
//************** OLD STOCK FUNCTIONS **************//
//*************************************************//
stock sh_Glow(id,r,g,b)
{
	if (!is_user_alive(id)) return
	set_user_rendering(id,kRenderFxGlowShell,r,g,b,kRenderNormal,16)
}
//----------------------------------------------------------------------------------------------
stock sh_Unglow(id)
{
	if (!is_user_alive(id)) return
	set_user_rendering(id)
}
//----------------------------------------------------------------------------------------------
stock sh_BPAmmoCS(wpnid) {

	new bpammo = 0
	switch (wpnid) {
		case CSW_P228			: bpammo = 52
		case CSW_SCOUT			: bpammo = 90
		case CSW_HEGRENADE		: bpammo = 1
		case CSW_XM1014		: bpammo = 32
		case CSW_C4			: bpammo = 0
		case CSW_MAC10			: bpammo = 100
		case CSW_AUG			: bpammo = 90
		case CSW_SMOKEGRENADE	: bpammo = 1
		case CSW_ELITE			: bpammo = 120
		case CSW_FIVESEVEN		: bpammo = 100
		case CSW_UMP45			: bpammo = 100
		case CSW_SG550			: bpammo = 90
		case CSW_GALI			: bpammo = 90
		case CSW_FAMAS			: bpammo = 90
		case CSW_USP			: bpammo = 100
		case CSW_GLOCK18		: bpammo = 120
		case CSW_AWP			: bpammo = 30
		case CSW_MP5NAVY		: bpammo = 120
		case CSW_M249			: bpammo = 200
		case CSW_M3			: bpammo = 21
		case CSW_M4A1			: bpammo = 90
		case CSW_TMP			: bpammo = 120
		case CSW_G3SG1			: bpammo = 90
		case CSW_FLASHBANG		: bpammo = 2
		case CSW_DEAGLE		: bpammo = 35
		case CSW_SG552			: bpammo = 90
		case CSW_AK47			: bpammo = 90
		case CSW_KNIFE			: bpammo = 0
		case CSW_P90			: bpammo = 100
	}
	return bpammo
}
//----------------------------------------------------------------------------------------------
stock sh_ClipAmmoCS(wpnid) {

	new clipammo = 0
	switch (wpnid) {
		case CSW_P228			: clipammo = 13
		case CSW_SCOUT			: clipammo = 10
		case CSW_HEGRENADE		: clipammo = 0
		case CSW_XM1014		: clipammo = 7
		case CSW_C4			: clipammo = 0
		case CSW_MAC10			: clipammo = 30
		case CSW_AUG			: clipammo = 30
		case CSW_SMOKEGRENADE	: clipammo = 0
		case CSW_ELITE			: clipammo = 15
		case CSW_FIVESEVEN		: clipammo = 20
		case CSW_UMP45			: clipammo = 25
		case CSW_SG550			: clipammo = 30
		case CSW_GALI			: clipammo = 35
		case CSW_FAMAS			: clipammo = 25
		case CSW_USP			: clipammo = 12
		case CSW_GLOCK18		: clipammo = 20
		case CSW_AWP			: clipammo = 10
		case CSW_MP5NAVY		: clipammo = 30
		case CSW_M249			: clipammo = 100
		case CSW_M3			: clipammo = 8
		case CSW_M4A1			: clipammo = 30
		case CSW_TMP			: clipammo = 30
		case CSW_G3SG1			: clipammo = 20
		case CSW_FLASHBANG		: clipammo = 0
		case CSW_DEAGLE		: clipammo = 7
		case CSW_SG552			: clipammo = 30
		case CSW_AK47			: clipammo = 30
		case CSW_KNIFE			: clipammo = 0
		case CSW_P90			: clipammo = 50
	}
	return clipammo
}
//----------------------------------------------------------------------------------------------
stock Float:maxof(Float: a, Float: b)
{
	if ( a >= b ) return a
	return b
}
//----------------------------------------------------------------------------------------------
stock Float:minof(Float: a, Float: b)
{
	if ( a <= b ) return a
	return b
}
//----------------------------------------------------------------------------------------------
stock sqrt(num)
{
	if (num > 0)	return sqroot(num)
	return 0
}
//----------------------------------------------------------------------------------------------
stock sh_OwnsWeaponID(id, weaponID )
{
	#if defined AMXX_VERSION
	return user_has_weapon(id,weaponID)
	#else

	new iwpn, iwpns[32]
	get_user_weapons(id, iwpns,iwpn)

	for(new a = 0; a < iwpn; a++) {
		if ( weaponID == iwpns[a] ) return true
	}
	return false

	#endif
}
//---------------------------------------------------------------------------------------------
stock sh_OwnsWeapon(id, weaponName[] )
{
	// Yeah just givem the weapon if they don't already have it
	new iwpn, iwpns[32]
	new ownWeapon[32]

	get_user_weapons(id, iwpns,iwpn)

	for(new a = 0; a < iwpn; a++) {
		get_weaponname(iwpns[a],ownWeapon,31)
		if ( equali(ownWeapon, weaponName) ) return true
	}
	return false
}
//---------------------------------------------------------------------------------------------
stock sh_GiveWeapon(id, weaponName[], bool:switchTo=false )
{
	if ( !is_user_alive(id) )  return
	if ( !sh_OwnsWeapon(id, weaponName) ) give_item(id, weaponName)
	if ( switchTo ) engclient_cmd(id, weaponName )
}
//---------------------------------------------------------------------------------------------
stock sh_GiveWeaponID(id, weaponID, bool:switchTo=false )
{
	if ( weaponID < CSW_P228 || weaponID > CSW_P90 || !is_user_alive(id) )  return

	new weaponName[32]
	get_weaponname(weaponID,weaponName,31)

	if ( !sh_OwnsWeaponID(id, weaponID) ) give_item(id, weaponName)
	if ( switchTo ) engclient_cmd(id, weaponName )
}
//---------------------------------------------------------------------------------------------
stock sh_SwitchWeaponID(id, weaponID )
{
	if ( weaponID < CSW_P228 || weaponID > CSW_P90 || !is_user_alive(id)  ) return

	if ( sh_OwnsWeaponID(id, weaponID) ) {
		new weaponName[32]
		get_weaponname(weaponID,weaponName,31)
		engclient_cmd(id, weaponName )
	}
}

//----------------------------------------------------------------------------------------------
// Default Sounds for heros
//----------------------------------------------------------------------------------------------
stock playSoundDenySelect(id)
{
	client_cmd(id,"spk common/wpn_denyselect.wav")
}